<script setup>
import { post } from "@/request/request";
import { onLoad } from "@dcloudio/uni-app";
import { ref } from "vue";
import TnIcon from '@tuniao/tnui-vue3-uniapp/components/icon/src/icon.vue'
import TnButton from '@tuniao/tnui-vue3-uniapp/components/button/src/button.vue'

const option = ref('');
const data = ref({})

onLoad((options) => {
  console.log('App onLoad', options);
  option.value = options;
  verify()
});


//核销网络请求
const verify = () => {
  post('/write_order', { orderSn: option.value.orderSn, hours: option.value.hourse }, { "Content-Type": "application/x-www-form-urlencoded", "sessionKey": uni.getStorageSync("sessionKey") }).then(res => {
    console.log('核销', res);
    data.value = res;
  })
}


/**
 * 第一个按钮是返回首页
 * 第二个按钮返回教师端
 */
const indexClick = () => {
  uni.switchTab({
    url: '/pages/index/index'
  });
}


const teacherClick = () => {
  uni.navigateBack({
    url: '/pages/user/components/teacher/teacher'
  })
}
</script>

<template>
  <view class="app">
    <view v-if="data.code === 200"
      style="width: 100%;display: flex;align-items: center;justify-content: center;flex-direction: column;margin: 80rpx;">
      <TnIcon name="success-circle" :size="200" color="#089a68" />
      <view style="font-size: 40rpx;color: #089a68;">{{ data.data.message }}</view>
      <view
        style="margin: 20rpx;display: flex;align-items: center;justify-content: space-around;flex-direction: column;height: 90rpx;">
        <view>订单号：{{ data.data.orderSn }}</view>
        <view>核销时间：{{ data.data.time }}</view>
      </view>
    </view>
    <view v-else style="width: 100%;display: flex;align-items: center;justify-content: center;flex-direction: column;">
      <TnIcon name="close-circle" :size="200" color="#ed6c89" />
      <view style="font-size: 40rpx;color: #ed6c89;">{{ data.message }}</view>
    </view>

    <view
      style="width: 100%;display: flex;align-items: center;justify-content: space-between;flex-direction: column;height: 180rpx;">
      <TnButton :width="686" :height="76" bg-color="#0045cf" text-color="#fff" @click="indexClick">返回首页</TnButton>
      <TnButton :width="686" :height="76" bg-color="#0045cf" text-color="#fff" @click="teacherClick">返回教师端</TnButton>
    </view>
  </view>
</template>




<style scoped lang="scss">
.app {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
</style>
